package com.hdaccp.ch04

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * spark streaming 入门
  *
  */
object Demo5 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(conf, Seconds(5))

    val lines = ssc.socketTextStream("192.168.15.11", 1234)

    lines.flatMap(x=>x.split(" ")).map(y=>(y,1)).reduceByKey(_+_).print()

    ssc.start()             // Start the computation
    ssc.awaitTermination()


  }
}
